package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

public class PaymentMainView extends JFrame implements ActionListener {

	/**
	 * 主界面
	 */
	private static final long serialVersionUID = 1L;
	private JMenuBar bar;
	private JMenuItem importPrepayDataItem, prepayStatisticItem, checkDataItem;
	private JMenuItem importReserveData, reserveStatisticItem;
	private JPanel panel1, panel2, panel4, panel5;
	JCheckBox depositButton;
	JCheckBox onlinePayButton;
	JCheckBox posPayButton;
	JCheckBox quaryButton;//

	public PaymentMainView() {
		super("第三方支付数据分析工具");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(700, 450);
		setLocationRelativeTo(this);
		setVisible(true);
		initiate();
		panel1 = new PrePaymentDataAccessPanel();
		panel2 = new PrePaymentAnalysisPanel();
		panel4 = new ReserveDataAccessPanel();
//		panel4 = new JPanel();
//		panel5 = new ReserveAnalysisPanel();
		panel5 = new JPanel();
		add(panel1);
		panel1.repaint();
		validate();

	}

	// 界面初始化
	private void initiate() {
		// 菜单栏
		bar = new JMenuBar();
		JMenu prepayEdit = new JMenu("预付卡管理");

		importPrepayDataItem = new JMenuItem("预付卡历史数据管理");
		// checkDataItem=new JMenuItem("预付卡交易信息");
		prepayStatisticItem = new JMenuItem("预付卡交易统计");
		prepayEdit.add(importPrepayDataItem);
		prepayEdit.add(prepayStatisticItem);
		// prepayEdit.add(checkDataItem);
		importPrepayDataItem.addActionListener(this);
		// checkDataItem.addActionListener(this);
		prepayStatisticItem.addActionListener(this);

		JMenu resrveEdit = new JMenu("备付金管理");
		importReserveData = new JMenuItem("导入备付金数据");
		reserveStatisticItem = new JMenuItem("统计和预测");
		resrveEdit.add(importReserveData);
		resrveEdit.add(reserveStatisticItem);
		importReserveData.addActionListener(this);
		reserveStatisticItem.addActionListener(this);

		bar.add(prepayEdit);
		bar.add(resrveEdit);
		this.setJMenuBar(bar);
		

	}

	// 不同功能页面间的转换
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == importPrepayDataItem) {
			try {

				this.getContentPane().removeAll();
				this.add(panel1);
				panel1.repaint();
				this.validate();

			} catch (Exception ee) {
				ee.printStackTrace();
			}
		} else if (e.getSource() == prepayStatisticItem) {
			try {

				this.getContentPane().removeAll();
				this.add(panel2);
				panel2.repaint();
				this.validate();
			} catch (Exception ee) {
				ee.printStackTrace();
			}
		} else if (e.getSource() == checkDataItem) {
			try {

				this.getContentPane().removeAll();
				// this.add(panel3);panel3.repaint();
				this.validate();
			} catch (Exception ee) {
				ee.printStackTrace();
			}
		} else if (e.getSource() == importReserveData) {
			try {
				this.getContentPane().removeAll();
				this.add(panel4);
				panel4.repaint();
				this.validate();

			} catch (Exception ee) {
				ee.printStackTrace();
			}
		} else if (e.getSource() == reserveStatisticItem) {
			try {
				this.getContentPane().removeAll();
				this.add(panel5);
				panel5.repaint();
				this.validate();
			} catch (Exception ee) {
				ee.printStackTrace();
			}
		}
	}

}
